package com.mogu.blogs.controller;


import com.mogu.blogs.service.FabuService;
import com.mogu.blogs.utils.RedisUtils;
import com.mogu.entity.TBlog;
import com.mogu.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/fabu")
public class FabuBlogController {

    @Autowired
    FabuService fabuService;
    @Autowired
    RedisUtils redisUtils;

    @PostMapping("/fabu")
    public String fabuBlog(@RequestBody TBlog tBlog){
        String fabu = fabuService.fabu(tBlog);
        if (fabu.equals("发布成功")){
            redisUtils.del(tBlog.getAuthor());
        }
        return "发布成功";
    }

    @PostMapping("/baocun")
    public String baocun(@RequestBody TBlog tBlog){
        return fabuService.baocun(tBlog);
    }

    @GetMapping("/zhanshi/{username}")
    public TBlog zhanshi(@PathVariable("username") String username){
        return fabuService.zhanshi(username);
    }
}
